unit U_SevkiyatHesListesi;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, DB, ADODB, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGrid, siComp;

type
  TfmSevkiyatHesabiSec = class(TForm)
    adoSevk: TADOQuery;
    DsSevk: TDataSource;
    Panel1: TPanel;
    bTamam: TBitBtn;
    BKapat: TBitBtn;
    cxgrid1: TcxGrid;
    cxgrid1DBTableView1: TcxGridDBTableView;
    cxgrid1Level1: TcxGridLevel;
    cxgrid1DBTableView1KODU: TcxGridDBColumn;
    cxgrid1DBTableView1ACIKLAMA: TcxGridDBColumn;
    cxgrid1DBTableView1TEL1: TcxGridDBColumn;
    cxgrid1DBTableView1ADRES1: TcxGridDBColumn;
    cxgrid1DBTableView1ADRES2: TcxGridDBColumn;
    cxgrid1DBTableView1ILCEAD: TcxGridDBColumn;
    cxgrid1DBTableView1SEHIRAD: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure bTamamClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BKapatClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure cxGrid1DBTableView1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cxGrid1DBTableView1ColumnHeaderClick(
      Sender: TcxGridTableView; AColumn: TcxGridColumn);
  private
    { Private declarations }
  public
    Aciklama: string;
    Kodu: string;
    ID: integer;
    CariID: integer;
  end;

var
  fmSevkiyatHesabiSec: TfmSevkiyatHesabiSec;

implementation
uses data, ana1;
{$R *.dfm}


procedure TfmSevkiyatHesabiSec.FormCreate(Sender: TObject);
begin
  Aciklama := '';
  Kodu := '';
  Id := 0;
end;

procedure TfmSevkiyatHesabiSec.bTamamClick(Sender: TObject);
begin
  anaform.MODALRESULT[1] := adoSevk.FieldValues['KODU'];
  anaform.MODALRESULT[2] := adoSevk.FieldValues['ACIKLAMA'];
  anaform.MODALRESULT[3] := adoSevk.FieldValues['ADRES1'];
  anaform.MODALRESULT[4] := adoSevk.FieldValues['ADRES2'];
  anaform.MODALRESULT[5] := adoSevk.FieldValues['ID'];
  anaform.MODALRESULT[6] := adoSevk.FieldValues['UNITYCODE'];

  ID := anaform.MODALRESULT[5];
  modalresult := mrOk;
end;

procedure TfmSevkiyatHesabiSec.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = 27 then ModalResult := mrCancel;
end;

procedure TfmSevkiyatHesabiSec.BKapatClick(Sender: TObject);
begin
  close;
end;

procedure TfmSevkiyatHesabiSec.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin

  action := Cafree;
  fmSevkiyatHesabiSec := nil;
end;

procedure TfmSevkiyatHesabiSec.FormShow(Sender: TObject);
begin
  if (Kodu <> '') or (Cariid <> 0) then begin
    adoSevk.Close;
    adosevk.SQL.Text := ' select * from tbl_SevkiyatAdres where ';
    adosevk.SQL.add(' KODU like :KODU');
    adosevk.Parameters.ParamByName('KODU').Value := Kodu + '%';

    if cariid <> 0 then begin
      adosevk.SQL.add(' and UNCARIID = :CID');
      adosevk.Parameters.ParamByName('CID').Value := Cariid;
    end;

    adosevk.SQL.add(' Order by KODU');
    adoSevk.Open;

    cxGrid1.SetFocus;
  end;

  if (Aciklama <> '') or (Cariid <> 0) then begin
    adoSevk.Close;
    adosevk.SQL.Text := ' select * from tbl_SevkiyatAdres where ';
    adosevk.SQL.add(' ACIKLAMA like :Aciklama');
    adosevk.Parameters.ParamByName('Aciklama').Value := Aciklama + '%';

    if cariid <> 0 then begin
      adosevk.SQL.add(' and UNCARIID = :CID');
      adosevk.Parameters.ParamByName('CID').Value := Cariid;
    end;

    adosevk.SQL.add(' Order by KODU');
    adoSevk.Open;

    cxGrid1.SetFocus;
  end;
end;

procedure TfmSevkiyatHesabiSec.cxGrid1DBTableView1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key = 13 then bTamamClick(sender);
end;

procedure TfmSevkiyatHesabiSec.cxGrid1DBTableView1ColumnHeaderClick(
  Sender: TcxGridTableView; AColumn: TcxGridColumn);
begin
  if AColumn.SortOrder = soAscending then
  begin
    adoSevk.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' DESC'
  end
  else
  begin
    adoSevk.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' ASC';
  end;

  cxgrid1DBTableView1.OptionsBehavior.IncSearchItem := AColumn;
end;

end.
